<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{$title}</title>
<include file='web/common:source'/>
<style>
div.layui-layer-shade{background-color:rgba(255,255,255,0) !important;}
div.layui-layer-rim{border:none; box-shadow:3px 5px 6px #dadada,-3px -1px 6px #dadada;}
div.layui-layer-title{background-color:#e2e5e8;}
</style>
</head>
<body ng-app="myApp" ng-controller="myAppControl">
<div class="mainBox m o">
    <div class="mainRight fr" style="padding-bottom:0px;">
        <include file='web/common:header'/>
        <div class="mainRightBot pr o">        
            <!-- leftMenu start -->
            <include file='web/common:left'/>
            <!-- leftMenu end -->
            <div class="rightBox fr" style="width:940px; min-height:900px;">
                <!-- rightBoxTop start -->
                <include file='web/project:common'/>
                <!-- rightBoxTop end -->              
                <!-- 项目详情 -->
                <div class="rightBoxBot">
                	<div class="rightBoxBotTop o afl">
						<a href="{:U('Project/index')}">返回上一级</a>
						<a href="{:U('Project/index')}" class="ts300">项目列表</a>
						<a class="lt"><i class="layui-icon" style="font-size: 16px;">&#xe602;</i></a>
						<a href="javascript:history.go(-1);" class="ts300">项目详情</a>
						<a class="lt"><i class="layui-icon" style="font-size: 16px;">&#xe602;</i></a>
						<a href="javascript:;" class="ts300">积分分配</a>
                	</div>
					<div class="personBox m" style="width:880px; border:none; margin-top:5px;">
					    <dl class="jifenDetails m pr" style="width:100%; padding-bottom:40px;">
					        <dt>积分总数(分)： <span>{$data['points']}</span></dt>
					        <!-- 
					        // 新增分配 allocate_id 0 代表新增分配,非0 代表重新分配
        					 -->
					        <dd class="ddRight part"><a href="javascript:;" ng-click="newAddFenpei(0)">+&nbsp;新增分配</a></dd>
					    </dl> 
					    <dl class="jifenTixian m" style="width:100%;">
					        <h3 class="f100">分配记录：</h3>
                            <if condition="count($data['allocates']) gt 0">
                                <ul class="jifenTixian">
                                    <foreach name="data[allocates]" item="x">
                                        <li><!-- {$x.status} -->
                                            <span class="fr" style="color:#9e9e9e;"><if condition="$x['status'] eq 0">分配中<elseif condition="$x['status'] eq 1" />已完成<else/>申诉</if>&nbsp;&nbsp;&nbsp;&nbsp;{$x.points}&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:;" ng-click="seeDetail({$x.id})" data-id="{$x.id}" style="color:#3296F3;">了解详情&nbsp;&gt;</a></span>
                                            <span class="fl" style="color:#9e9e9e;">{$x.serial}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$x.updated_at}</span>
                                        </li>
                                    </foreach>
                                </ul>
                            <else />
                                <div class="bottomBox">暂无分配记录</div>
                            </if>
					    </dl>
					</div>           
                </div>
                <!-- 新建订单 弹出层 start -->
                <include file='web/common:createDingdan'/>
                <!-- 新建订单 弹出层 end -->
                <!-- 新建项目 弹出层 新建项目 start -->
                <include file='web/common:createProject'/>
                <!-- 新建项目 弹出层 end -->
                <!-- 新建合同 弹出层 start -->
                <include file='web/common:createHetong'/>
                <!-- 新建合同 弹出层 end -->
                <div id="jifenShadow" style="display: none;">
					<div class="w100 o">
						<div class="w120 o">
	                        <div class="shadowBoxLeft fl" style="width:500px;">
	                            <div class="shadowBoxLeftBox m">
	                            	<div style="padding:5px 0px 20px; font-size:18px; border-bottom:1px solid #ddd; text-align:center; color:#6b6b6b;">剩余积分（分）： <span style="font-size:30px; color:#21b1e7;" id="shengyuJifen">{{shengyuJifen}}</span></div>
	                                <div class="noPerson dn"></div>
	                                <div class="projectPerson" style="margin-top:15px;">
	                                    <!-- list start -->
	                                    <dl ng-repeat="x in curProjectPerson | filter:curSerchStr" class="projectPerson pr">
	                                        <dt class="palt" ng-hide="{{x.avatar | showFace }}" style="top:25px;">{{x.name | nameStr}}</dt>
	                                        <dt class="palt face" ng-show="{{x.avatar | showFace }}" style="top:25px;"><img ng-src="{{x.avatar}}" alt="" ></dt>
	                                        <dd class="fl">
	                                            <h3 class="f100">{{x.name}}<span class="palt" style="left:160px; top:3px;">{{x.mobile}}</span></h3>
	                                            <h4 class="f100"><span class="bumeng">部门：{{x.department}}</span><span class="zhiwei">&nbsp;&nbsp;&nbsp;&nbsp;职位：{{x.position}}</span></h4>
	                                            <h4 class="f100"><span class="bumeng">角色：{{x.type | typeStr}}</span></h4>
	                                            <h4 class="f100 o">
	                                                <span class="bumeng danrenzhiwei fl">备注：{{x.remark}}</span>
	                                            </h4>
                                                <h4 class="f100 o">
                                                    <span class="bumeng danrenzhiwei fl" ng-show="{{x.points | pointeShow}}">当前积分：{{x.points}}</span>
                                                </h4>
                                                <h4 class="f100 o">
                                                    <span class="bumeng danrenzhiwei fl" ng-show="{{x.allocate_status | allocateReasonShow}}">申诉原因：{{x.allocate_reason}}</span>
                                                </h4> 
	                                        </dd>
	                                        <dd class="part tc">
	                                       	<!-- allocateStatus -->
	                                        	<h3 class="f100 h3FenpeiJifen" ng-show="x.allocate_status | jifenShow" style="padding-left:2px; padding-bottom:5px;">{{x.allocate_points}}</h3>
	                                            <h3 class="f100 cp h3Fenpei" data-nameStr="{{x.name}}" style="padding:2px 10px; background:#3296fa; color:#fff; border-radius:5px;">{{x.allocate_status | allocateStatus}}</h3>
                                                <div class="dn" style="display:none;">
                                                    <span class="user_id">{{x.user_id}}</span>
                                                    <span class="type">{{x.type}}</span>
                                                    <span class="remark">{{x.remark}}</span>
                                                    <span class="allocate_record_id ">{{x.allocate_record_id }}</span>
                                                    <span class="allocate_points"></span>
                                                </div>
	                                        </dd>
	                                    </dl>
	                                    <!-- list end -->
	                                    <div class="confirmJifen" ng-show="show_allocate_button" style="width:180px; margin:0px auto;"><button style="width:180px; height:45px; line-height:45px; cursor:pointer; text-align:center; font-size:16px; color:#fff; background:#3296fa; border-radius:5px; margin:30px auto;">确认积分分配</button></div>
	                                </div>
	                            </div>
	                        </div>
	                    </div>
					</div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<include file='web/common:footer'/>
<script type="text/javascript">
// angular start
(function(){
    var hostUrl = "http://"+"<?php echo $_SERVER['HTTP_HOST']; ?>/";
    var getAllocateParamUrl = hostUrl+"project/getAllocateParam"; // 获取积分分配详情 
    var allocatePointsUrl = hostUrl+"project/allocatePoints"; // 项目积分分配  
    var myApp = angular.module("myApp",[]);
    var type = <?php echo $_GET['type']?>;
    var project_id = <?php echo $_GET['project_id']?>;
    var shengyuJifen = {$data['points']};
    var allocate_id = 0;
    // 所有人员列表 
    myApp.controller('myAppControl',['$scope','$http',function($scope,$http){
        $scope.shengyuJifen = shengyuJifen;
        $scope.show_allocate_button = true;
        // 新增分配 allocate_id 0 代表新增分配,非0 代表重新分配 
        $scope.newAddFenpei = function(allocate_id){
            allocate_id = 0;        
        	ajaxGet(getAllocateParamUrl,{project_id:project_id,type:type,allocate_id:0},function(res){
                if(res.data.code == -1){
                    layer.alert(res.data.message);
                    return false;
                };
                $scope.show_allocate_button = res.data.data.show_allocate_button;
        		if(res.status == 200 && res.statusText == "OK"){
        			//if(res.data.data.members.length == 0){
        			//	layer.msg('请先去添加项目成员');
        			//}else{
        				$scope.curProjectPerson = res.data.data.members;
                        comLayeropen();
        			//};
        		}else{
        			layer.msg(res.statusText);
        		};
        	});
        };
        // 点击了解详情 
        $scope.seeDetail = function(listId){
            allocate_id = listId;
            //console.log(listId);
            ajaxGet(getAllocateParamUrl,{project_id:project_id,type:type,allocate_id:listId},function(res){
                if(res.data.code == -1){
                    layer.alert(res.data.message);
                    return false;
                };
                $scope.show_allocate_button = res.data.data.show_allocate_button;
                if(res.status == 200 && res.statusText == "OK"){
                    // if(res.data.data.members.length == 0){
                    //     layer.msg('请先去添加项目成员');
                    // }else{
                        //console.log(res.data.data.members);
                        $scope.curProjectPerson = res.data.data.members;
                        comLayeropen();
                    //};
                }else{
                    layer.msg(res.statusText);
                };
            });
        };
        function comLayeropen(res){            
            layer.open({
                type: 1,
                title: ['项目人员列表', 'font-size:18px;'],
                skin: 'layui-layer-rim', //加上边框
                area: ['500px', '650px'], //宽高
                content: $("#jifenShadow")
            });
        };
        function ajaxGet(url,data,fun){
            $http.get(url,{params:data}).then(function(res){
                fun(res);
            });
        };
        function ajaxPost(url,data,fun){
            $http.post(url,{params:data}).then(function(res){
                fun(res);
            });
        };
    }]);
    // 分配积分
    $("div.projectPerson dl.projectPerson").find("h3.h3Fenpei").live('click',function(e){
        if($(this).html() == "已分配"){
            layer.alert('你已经分配过!', {icon: 5});
            return false;
        };
        var nameStr = "确认给"+$(this).attr('data-nameStr')+"分配积分";
        var that = $(this);
        layer.prompt({
            formType: 0,
            value: '0',
            title: nameStr,
        }, function(value, index, elem){
            if(value == 0){
                layer.close(index);
                that.siblings("h3.h3FenpeiJifen").addClass('ng-hide').html('');
                setTimeout(function(){ 
                    comJifenFun();
                },100);
                return false;
            };
            if(isNaN(value)){ 
                layer.alert('积分必须是一个数字', {icon: 5});
                return false;
            };            
            if(value>shengyuJifen){ 
               layer.alert('分配的积分不能大于剩余积分',{icon:5});
              return false;
            };
            that.siblings("h3.h3FenpeiJifen").removeClass('ng-hide').html(value);
            that.siblings("div.dn").find("span.allocate_points").html(value);
            // allocate_points
            setTimeout(function(){ 
                comJifenFun();
            },100);
            function comJifenFun(){
                var allAddJifen = shengyuJIfen();
                var spanJifen = shengyuJifen - allAddJifen;
                if(spanJifen < 0){
                    layer.alert('积分分配错误',{icon:5});
                    return false;
                };
                $("span#shengyuJifen").html(spanJifen);                
                layer.close(index);
            };            
        });
    });
    // 确认积分分配
    $("div.projectPerson div.confirmJifen").click(function(){
        var dataJson = {};
        dataJson.project_id = <?php echo $_GET['project_id']?>;
        dataJson.type = <?php echo $_GET['type']?>;
        dataJson.members = jiFenarr();
        dataJson.allocate_id = allocate_id;
        $.post(allocatePointsUrl,dataJson,function(res){
            if(res.message == "OK"){
                layer.confirm('分配成功',{
                    btn: ['确定']},
                function(){
                    location.reload();
                });
            }else{
                layer.alert(res.message,{icon:2});
            }; 
        });
    });    
    function jiFenarr(){
        var jiFenArr = [];
        $("div.projectPerson dl.projectPerson").each(function(index,item){
            // ng-hide
            if(!$(this).find("h3.h3FenpeiJifen").hasClass('ng-hide')){
                var jsFenChildStr = {};
                jsFenChildStr.user_id = $(this).find("span.user_id").html();
                jsFenChildStr.type = $(this).find("span.type").html();
                jsFenChildStr.remark = $(this).find("span.remark").html();
                jsFenChildStr.allocate_record_id = $(this).find("span.allocate_record_id").html();
                jsFenChildStr.allocate_points = $(this).find("span.allocate_points").html();
                jiFenArr.push(jsFenChildStr);
            };
        });
        return jiFenArr;
    };
    function shengyuJIfen(){
        var shengyuJifen = 0;
        $("div.projectPerson dl.projectPerson").each(function(index,item){
            var shengyuJifenStr = $(this).find("h3.h3FenpeiJifen").html();
            if(shengyuJifenStr != ""){
                shengyuJifen += parseInt(shengyuJifenStr);
            };
        });
        return shengyuJifen;
    };
    myApp.filter('showFace', function() {
        return function(text) {
            if(text == ""){
                return false;
            }else{
                return true;
            };
        }
    });
    myApp.filter('pointeShow',function(){
        return function(text) {
            if(text == "" || text == null){
                return false;
            }else{
                return true;
            };
        }
    });
    myApp.filter('allocateReasonShow',function(){
        return function(text) {
            if(text == "" || text == null){
                return false;
            }else{
                return true;
            };
        }
    });
    myApp.filter('nameStr',function(){
        return function(nameStr){
            if(nameStr.length>2){
                return nameStr.substr(-2);
            }else{
                return nameStr;
            };
        }
    }); 
	myApp.filter('typeStr',function(){
        return function(typeStr){
        	var strType = "";
        	// 0-普通成员,1-专业负责人,2-项目负责人
        	if(typeStr == 0){
        		strType = "普通成员";
        	}else if(typeStr == 1){
        		strType = "专业负责人";
        	}else if(typeStr == 2){
        		strType = "项目负责人";
        	};
        	return strType;
        }
    });    
	myApp.filter('allocateStatus',function(){
        return function(allocateStatus){
        	var statusStr = "";
        	// 成员分配状态：0-未分配,1-已分配,2-重新分配
        	if(allocateStatus == 0){
        		statusStr = "分配";
        	}else if(allocateStatus == 1){
        		statusStr = "已分配";
        	}else if(allocateStatus == 2){
        		statusStr = "重新分配";
        	};
        	return statusStr;
        }
    });
    myApp.filter('jifenShow',function(){
    	return function(allocateStatus){
    		if(allocateStatus == 0){
    			return false;
    		}else{
    			return true;
    		};
    	}
    });
    myApp.filter('showComment',function(){
        return function(comment){
            if(comment == ""){
                return false;
            }else{
                return true;
            };
        }
    });    
})();
// jifenShadow();
// function jifenShadow(){   
//     layer.open({
//         type: 1,
//         title: ['项目人员列表', 'font-size:18px;'],
//         skin: 'layui-layer-rim', //加上边框
//         area: ['500px', '650px'], //宽高
//         content: $("#jifenShadow")
//     });
// }; 
</script>
</html>